package mess;

import com.sun.jndi.ldap.Ber;

public class LeeCode_28 {
    public static void main(String[] args) {
        String haystack = "mississippi";
        String needle = "issipi";
        System.out.println(strStr(haystack, needle));
    }
    private static int strStr(String haystack, String needle) {
        int len1 = haystack.length();
        int len2 = needle.length();
        if (len2 > len1)
            return -1;
        for (int i = 0; i < len1; i++) {
            for (int j = 0; j < len2; j++) {
                if (i + j > len1 - 1)
                    return -1;
                char c1 = haystack.charAt(i + j);
                char c2 = needle.charAt(j);
                if (c1 != c2)
                    break;
                if (j == len2 - 1)
                    return i;
            }
        }
        return -1;
    }
}
